package com.ssm.service.impl;

import com.ssm.dao.DepartmentnameMapper;
import com.ssm.entity.Departmentname;
import com.ssm.entity.DepartmentnameExample;
import com.ssm.service.DepartmentService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("Departmentname")
public class DepartmentServiceImpl implements DepartmentService {
    protected Logger logger= LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
    @Resource(name = "departmentnameMapper")
    private DepartmentnameMapper departmentnameMapper;
    @Override
    public List<Departmentname> listAllDepartment() {
        return departmentnameMapper.selectByExample(new DepartmentnameExample());
    }

    @Override
    public Integer createDepartment(Departmentname departmentname) {
        return departmentnameMapper.insert(departmentname);
    }

    @Override
    public Integer update(Departmentname departmentname) {
        return departmentnameMapper.updateByPrimaryKey(departmentname);
    }

    @Override
    public Integer deleteDepartment(int id) {
        return departmentnameMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Departmentname getDepartment(int id) {
        return departmentnameMapper.selectByPrimaryKey(id);
    }

    @Override
    public String Departmentidtoname(int id) {
        return getDepartment(id).getdepartmentname();
    }
    public Departmentname nametoDepartment(String name){

        DepartmentnameExample departmentnameExample =new DepartmentnameExample();
        departmentnameExample.or().anddepartmentnameEqualTo(name);
        List<Departmentname> departmentname= departmentnameMapper.selectByExample(departmentnameExample);
        if(departmentname.isEmpty()){
            logger.error("没有根据部门名字查到id");
        }
        Departmentname departmentname1= departmentname.get(0);
        return departmentname1;
    }
}
